local hx__yanzhan = fk.CreateSkill {
  name = "hx__yanzhan",
  tags = { Skill.Limited },
}


hx__yanzhan:addEffect("active", {
  name = "hx__yanzhan",
  prompt = "#hx__yanzhan",
  card_num = 0,
  target_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(hx__yanzhan.name, Player.HistoryGame) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = effect.from
    if player.general == "klother__liuchen" then
      player.general = "klother2__liuchen"
      room:broadcastProperty(player, "general")
    elseif player.deputyGeneral == "klother__liuchen" then
      player.deputyGeneral = "klother2__liuchen"
      room:broadcastProperty(player, "deputyGeneral")
    end
    for _, p in ipairs(room:getAlivePlayers()) do
      if p:isAlive() then
        local diff = 1 - p.hp
        if diff ~= 0 then
          room:changeHp(p, diff, nil, hx__yanzhan.name)
        end
        if p == player then
          diff = math.min(diff, 0) - 2
        end
        if diff < 0 then
          room:changeShield(p, -diff)
        end
      end
    end
    room:setBanner("@[:]hx__yanzhan-ing", "hx__yanzhan-guanghuan")
    for _, id in ipairs(room.draw_pile) do
      local card = Fk:getCardById(id)
      if card.name == "analeptic" or card.name == "peach" or card.name == "jink" then
        room:addCardMark(card, "hx__yanzhan-guanghuan", 1)
      end
    end
    for _, id in ipairs(room.discard_pile) do
      local card = Fk:getCardById(id)
      if card.name == "analeptic" or card.name == "peach" or card.name == "jink" then
        room:addCardMark(card, "hx__yanzhan-guanghuan", 1)
      end
    end
    for _, p in ipairs(room:getAlivePlayers()) do
      local cards = table.filter(p:getCardIds("hej"), function(id)
        return Fk:getCardById(id).name == "analeptic" or Fk:getCardById(id).name == "peach"
      or Fk:getCardById(id).name == "jink"
      end)
      for _, id in ipairs(cards) do
        local card = Fk:getCardById(id)
        room:addCardMark(card, "hx__yanzhan-guanghuan", 1)
      end
    end
  end,
})

hx__yanzhan:addEffect("filter", {
  name = "hx__yanzhan",
  mute = true,
  global = true,
  card_filter = function(self, card, player)
    return card:getMark("hx__yanzhan-guanghuan") ~= 0 and table.contains(player:getCardIds("h"), card.id)
  end,
  view_as = function(self, player, card)
    return Fk:cloneCard("duel", card.suit, card.number)
  end,
})

return hx__yanzhan